package com.bdzt.beidoubox.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bdzt.beidoubox.R;
import com.bdzt.beidoubox.entity.MessageBean;

import java.util.List;

/**
 * Created by 、默 on 4/5/2017.
 */

public class MessageAdapter extends BaseAdapter {
    private List<MessageBean> list;
    private Context mContext;
    private LayoutInflater inflater;

    public MessageAdapter(List<MessageBean> list, Context mContext) {
        this.mContext=mContext;
        this.list=list;
        inflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null||view.getTag()==null){
            holder=new ViewHolder();
            view= inflater.inflate(R.layout.message_item,viewGroup,false);
            holder.tv_itemContext= (TextView) view.findViewById(R.id.tv_itemContext);
            holder.tv_itemDate= (TextView) view.findViewById(R.id.tv_itemDate);
            holder.tv_itemTitle= (TextView) view.findViewById(R.id.tv_itemTitle);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }


        holder.tv_itemContext.setText(list.get(i).getContext());
        holder.tv_itemDate.setText(list.get(i).getDate());
        holder.tv_itemTitle.setText(list.get(i).getTitle());
        return view;
    }

    class ViewHolder{
        private TextView tv_itemTitle;
        private TextView tv_itemDate;
        private TextView tv_itemContext;
    }

}
